import createElement from "./createElement";
import updateChildren from "./updateChildren";
export default function patchVNode(oldVNode, newVNode) {
    // 针对同一节点比较差异，并更新
    // 如果newVNode存在children则不存在text
    if(newVNode.children && newVNode.children.length > 0) {
        if(oldVNode.children && oldVNode.children.length > 0) {
            console.log(oldVNode, 'oldVNode111111')
            // 新旧节点都含有children
            updateChildren(oldVNode.elm, oldVNode.children, newVNode.children)
        } else {
            oldVNode.elm.innerText = ''
            // 旧节点只有text
            newVNode.children.forEach(el => {
                oldVNode.elm.appendChild(createElement(el))
            })
        }

    } else {
        // 存在text不存在children
        // 新覆盖旧
        console.log(newVNode,'newVNode')
        console.log(oldVNode,'oldVNode')
        if(oldVNode.text != newVNode.text){
            oldVNode.elm.innerText = newVNode.text
        }
    }
}
